<?php

class WorkshiftController extends RController
{

    /**
     * @return array action filters
     */
    public function filters()
    {
        return array('rights');
    }

    public function actionIndex()
    {
        $cs = Yii::app()->clientScript;
        $cs->scriptMap = array(
            'jquery.js' => false,
        );
        $workshift = new Workshift();
        $this->render('index', array(
            'dataProvider' => new CActiveDataProvider($workshift)
        ));
    }

    public function actionUpdate()
    {
        $assetsUrl = $this->module->getAssetsUrl();
        $cs = Yii::app()->getClientScript();
        $cs->registerScriptFile($assetsUrl . '/js/bootstrap-timepicker.js');
        $cs->registerCssFile($assetsUrl . '/css/bootstrap-timepicker.css');

        $id = Yii::app()->getRequest()->getQuery('id');
        $model = Workshift::model()->findByPk($id);

        if (isset($_POST['Workshift'])) {
            $model->setAttributes($_POST['Workshift']);
            if ($model->validate() && $model->save()) {
                Yii::app()->user->setFlash('success', UserModule::t('You have updated "Workshift" successfully.'));
            } else {
                Yii::app()->user->setFlash('error', 'Có lỗi xảy ra');
            }
        }


        $this->render('_form', array(
            'model' => $model
        ));
    }

}
